package tt;

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Five {
    public static void main(String[] args) {
        QQ();
    }
    static class tim {
        int l;
        int r;
    }

    public static void QQ() {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        tim[] time = new tim[n];
        int t[] = new int[n * 2];
        for (int i = 0; i < 2 * n; i++) {
            t[i] = scanner.nextInt();
        }
        for (int i = 0; i < time.length; i++) {
            time[i] = new tim();
        }
        for (int i = 0; i < n; i++) {
            int x = t[i * 2];
            int y = t[i * 2 + 1];
            if (x > y) {
                y = y + m;
            }
            time[i].l = x;
            time[i].r = y;
        }
        Arrays.sort(time, new Comparator<tim>() {
            public int compare(tim a, tim b) {
                return a.r - b.r;
            }
        });
        int ans = 0;
        int tmpl = 0;
        int tmpr = 0;
        for (int i = 0; i < n; i++) {
            if (time[i].l > m || time[i].r > m)
                continue;
            if (time[i].l >= tmpr) {
                ans++;
                tmpl = time[i].l;
                tmpr = time[i].r;
            }
        }
        System.out.println(ans);
    }
}
